<template>
    <div class="container" v-if="DetailArr.length != 0 && LyricArr.length != 0">
        <div class="playListDetail">
            <div class="playListDetail-left">
                <div class="playListDetail-left-message">
                    <div class="message-left">
                        <div class="message-left-img">
                            <img :src="DetailArr.songs[0]?.al.picUrl" alt="">
                            <span></span>
                        </div>
                        <div class="message-left-out">
                            <i></i>
                            <a href="">生成外链播放器</a>
                        </div>
                    </div>
                    <div class="message-right">
                        <div class="message-right-1">
                            <i></i>
                            <div class="message-right-1-title">
                                <em v-if="DetailArr?.songs">{{ DetailArr?.songs[0]?.name }}</em>
                                <div v-if="DetailArr?.songs[0]?.alia[0]" class="summary">{{ DetailArr?.songs[0]?.alia[0] }}
                                </div>
                            </div>
                        </div>
                        <div class="message-right-2" v-if="DetailArr?.songs[0]?.ar">
                            歌手：<span><a href="">{{ DetailArr?.songs[0]?.ar[0].name }}</a></span>
                        </div>
                        <div class="message-right-2" v-if="DetailArr?.songs[0]?.al">
                            所属专辑：<a href="">{{ DetailArr?.songs[0]?.al.name }}</a>
                        </div>
                        <div class="message-right-btn">
                            <a href="javascript:;" class="btn-play">
                                <i @click="getSingId(route.query.id)">
                                    <em></em>播放
                                </i>
                            </a>
                            <a href="javascript:;" class="btn-add"></a>
                            <a href="javascript:;" class="btn-fav">
                                <i>收藏</i>
                            </a>
                            <a href="javascript:;" class="btn-share">
                                <i>分享</i>
                            </a>
                            <a href="javascript:;" class="btn-dl">
                                <i>下载</i>
                            </a>
                            <a href="javascript:;" class="btn-cmmt">
                                <i>(<span>99</span>)</i>
                            </a>
                        </div>
                        <div class="lyric-content">
                            <div class="lyric-list" :class="LyricFlag ? 'big' : 'small'">
                                <div v-for="(item, index) in LyricArr?.split('\n')" :key="index">
                                    <span>{{ item.includes(']') ? item.split(']')[1] : item }}</span><br>
                                </div>
                            </div>
                            <div class="crl" v-if="LyricArr?.split('\n').length > 11" @click="LyricFlag = !LyricFlag">
                                <span v-if="LyricFlag">收起</span>
                                <span v-else>展开</span>
                                <i :class="LyricFlag ? 'sq' : 'zk'"></i>
                            </div>
                        </div>

                    </div>
                </div>
                <div class="playListDetail-left-comment">
                    <div class="comment-title">
                        <h3>
                            <span>评论</span>
                        </h3>
                        <span>共1317条评论</span>
                    </div>
                    <div class="comment-input">
                        <div class="comment-input-box">
                            <div class="comment-input-box-left">
                                <img src="../../assets/images/default_avatar.jpg" alt="">
                            </div>
                            <div class="comment-input-box-right">
                                <div class="comment-input-box-right-textarea" @click="getinput">
                                    <textarea  :maxlength="140" v-model="textareaVal" placeholder="评论" :disabled="disabledFlag"></textarea>
                                </div>
                                <div class="comment-input-box-btns">
                                    <i class="btn-expression" @click="emojiFlag=true"></i>
                                    <i class="btn-at"></i>
                                    <i class="btn-comment">评论</i>
                                    <span class="comment-num">{{commentNum - textareaVal.length}}</span>
                                </div>
                                <div class="corr">
                                    <em>◆</em>
                                    <i>◆</i>
                                </div>
                                <div class="emoji" v-if="emojiFlag" ref="target">
                                    <EmojiPicker :options="{
                                        native: true, locals: 'en', footer: false,hasGroupIcons: true, hasSearch: false,
                                        hasGroupNames: false, stickyGroupNames: false, hasSkinTones: false,
                                        recentRecords: false,
                                    }" @select="selectEmoji" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="playListDetail-right">

            </div>
        </div>
    </div>
</template>
<script setup lang="ts">
import { useRoute } from 'vue-router';
import { onMounted, ref } from 'vue';
import { reqSingDetail, reqSingLyric } from '../../api/songDetail/index';
import { EmojiPicker } from 'vue3-twemoji-picker-final'
import '../../../node_modules/vue3-twemoji-picker-final/dist/index.css'
import playerStore from '@/store/modules/player';
import loginStore from '@/store/modules/login';
import { onClickOutside } from '@vueuse/core'
let route = useRoute()
let DetailArr = ref<any>([])
let LyricArr = ref<any>([])
let LyricFlag = ref(false)
let emojiFlag = ref(false)
let textareaVal = ref('')
let playerUseStore = playerStore()  
let loginUseStore = loginStore()
let target = ref(null)
let commentNum = ref(140)
let disabledFlag = ref(false)
onMounted(() => {
    getSingDetail(route.query.id)
    getSingLyric(route.query.id)
})
const getSingDetail = async (ids: any) => {
    let result = await reqSingDetail(ids)
    if (result.code == 200) {
        DetailArr.value = result
    }
}
const getSingLyric = async (id: any) => {
    let result = await reqSingLyric(id)
    if (result.code == 200) {
        LyricArr.value = result.lrc.lyric
    }
}
const selectEmoji = (e:any)=>{
    textareaVal.value+=e.i
}
const closeEmoji = ()=>{
    emojiFlag.value = false
}
onClickOutside(target,closeEmoji)
const getSingId = async (id: any) => {
    await playerUseStore.getsingMessage(id)
}
const getinput = ()=>{
    if(loginUseStore.cookie==null){
        loginUseStore.flag = true
        disabledFlag.value = true
    }else{
        disabledFlag.value = false
    }
}
</script>

<style scoped lang="less">
.playListDetail {
    width: 100%;
    display: flex;

    .playListDetail-left {
        width: 709px;
        padding: 47px 30px 40px 39px;

        .playListDetail-left-message {
            margin-top: -10px;

            &::after {
                content: '';
                display: block;
                clear: both;
            }

            .message-left {
                float: left;
                width: 206px;
                margin-right: -226px;

                .message-left-img {
                    width: 198px;
                    height: 198px;
                    position: relative;

                    img {
                        width: 130px;
                        height: 130px;
                        margin: 34px;
                    }

                    span {
                        display: block;
                        position: absolute;
                        width: 206px;
                        height: 205px;
                        top: -4px;
                        left: -4px;
                        background: url(../../assets/images/coverall.png) no-repeat;
                        background-position: -140px -580px;
                    }
                }

                .message-left-out {
                    float: left;
                    margin: 20px 0 0 46px;
                    display: flex;
                    align-items: center;

                    i {
                        display: block;
                        width: 16px;
                        height: 16px;
                        background: url(../../assets/images/icon.png) no-repeat;
                        background-position: -34px -863px;
                    }

                    a {
                        margin: 10px 0;
                        font-size: 12px;
                        color: #0c73c2;
                    }
                }
            }

            .message-right {
                float: right;
                width: 414px;

                .message-right-1 {
                    display: flex;
                    align-items: flex-start;

                    i {
                        float: left;
                        display: block;
                        width: 54px;
                        height: 24px;
                        background: url(../../assets/images/icon.png) no-repeat;
                        background-position: 0 -463px;
                    }

                    .message-right-1-title {
                        margin-left: 10px;
                        position: relative;
                        font-size: 24px;

                        em {
                            margin-right: 7px;
                            display: block;
                            font-style: normal;
                            margin-bottom: 5px;
                        }

                        .summary {
                            margin: 1px 0 5px;
                            color: #bababa;
                            font-size: 14px;
                        }
                    }
                }

                .message-right-2 {
                    margin: 10px 0;
                    color: #999;
                    font-size: 12px;

                    a {
                        color: #0c73c2;

                        &:hover {
                            text-decoration: underline;
                        }
                    }
                }

                .message-right-btn {
                    margin-bottom: 38px;
                    margin-right: -10px;
                    overflow: hidden;

                    &::after {
                        content: '';
                        display: table;
                        clear: both;
                    }

                    .btn-play {
                        color: #fff;
                        float: left;
                        background: url(../../assets/images/button2.png);
                        background-position: right -428px;
                        padding: 0 5px 0 0;
                        height: 31px;
                        line-height: 31px;

                        i {
                            padding: 0 7px 0 8px;
                            height: 31px;
                            line-height: 31px;
                            display: block;
                            font-size: 12px;
                            color: #fff;
                            background: url(../../assets/images/button2.png);
                            background-position: 0 -387px;

                            em {
                                float: left;
                                width: 20px;
                                height: 18px;
                                margin: 6px 2px 2px 0;
                                background: url(../../assets/images/button2.png);
                                background-position: 0 -1622px;
                                overflow: hidden;
                            }
                        }
                    }

                    .btn-add {
                        display: block;
                        padding: 0 5px 0 0;
                        margin-right: 5px;
                        width: 31px;
                        margin-left: -3px;
                        padding-right: 0;
                        background: url(../../assets/images/button2.png);
                        background-position: 0 -1588px;
                        float: left;
                        height: 31px;
                        line-height: 30px;
                        min-width: 23px;
                        cursor: pointer;
                    }

                    .btn-fav {
                        float: left;
                        height: 31px;
                        line-height: 30px;
                        min-width: 23px;
                        cursor: pointer;
                        color: #333;
                        padding: 0 5px 0 0;
                        margin-right: 6px;
                        background: url(../../assets/images/button2.png);
                        background-position: right -1020px;

                        i {
                            background: url(../../assets/images/button2.png);
                            background-position: 0 -977px;
                            padding-right: 2px;
                            padding-left: 28px;
                            padding: 0 7px 0 28px;
                            float: left;
                            height: 31px;
                            line-height: 30px;
                            min-width: 23px;
                            cursor: pointer;
                            font-size: 12px;
                        }
                    }

                    .btn-share {
                        float: left;
                        height: 31px;
                        line-height: 30px;
                        min-width: 23px;
                        cursor: pointer;
                        color: #333;
                        padding: 0 5px 0 0;
                        margin-right: 6px;
                        background: url(../../assets/images/button2.png);
                        background-position: right -1020px;

                        i {
                            background: url(../../assets/images/button2.png);
                            background-position: 0 -1268px;
                            padding-right: 2px;
                            padding-left: 28px;
                            padding: 0 7px 0 28px;
                            float: left;
                            height: 31px;
                            line-height: 30px;
                            min-width: 23px;
                            cursor: pointer;
                            font-size: 12px;
                        }
                    }

                    .btn-dl {
                        float: left;
                        height: 31px;
                        line-height: 30px;
                        min-width: 23px;
                        cursor: pointer;
                        color: #333;
                        padding: 0 5px 0 0;
                        margin-right: 6px;
                        background: url(../../assets/images/button2.png);
                        background-position: right -1020px;

                        i {
                            background: url(../../assets/images/button2.png);
                            background-position: 0 -2761px;
                            padding-right: 2px;
                            padding-left: 28px;
                            padding: 0 7px 0 28px;
                            float: left;
                            height: 31px;
                            line-height: 30px;
                            min-width: 23px;
                            cursor: pointer;
                            font-size: 12px;
                        }
                    }

                    .btn-cmmt {
                        float: left;
                        height: 31px;
                        line-height: 30px;
                        min-width: 23px;
                        cursor: pointer;
                        color: #333;
                        padding: 0 5px 0 0;
                        margin-right: 6px;
                        background: url(../../assets/images/button2.png);
                        background-position: right -1020px;

                        i {
                            background: url(../../assets/images/button2.png);
                            background-position: 0 -1465px;
                            padding-right: 2px;
                            padding-left: 28px;
                            padding: 0 7px 0 28px;
                            float: left;
                            height: 31px;
                            line-height: 30px;
                            min-width: 23px;
                            cursor: pointer;
                            font-size: 12px;
                            font-family: simsun, 宋体;
                        }
                    }
                }

                .lyric-content {
                    font-size: 12px;

                    .lyric-list {
                        line-height: 23px;

                        color: #333;

                        &.small {
                            max-height: 253px;
                            overflow: hidden;
                        }

                        &.big {
                            max-height: auto;
                        }
                    }

                    .crl {
                        margin-top: 10px;
                        color: #0c73c2;
                        width: fit-content;
                        cursor: pointer;

                        i {
                            width: 11px;
                            height: 8px;
                            display: inline-block;
                            overflow: hidden;
                            vertical-align: middle;
                            background-image: url('../../assets/images/icon.png');

                            &.zk {
                                background-position: -65px -520px;
                            }

                            &.sq {
                                background-position: -65px -520px;
                                background-position: -45px -520px;
                            }
                        }
                    }
                }
            }
        }

        .playListDetail-left-comment {
            margin-top: 40px;
            height: 33px;
            border-bottom: 2px solid #c20c0c;

            .comment-title {
                &::after {
                    content: '';
                    display: block;
                    clear: both;
                }

                h3 {
                    font-size: 20px;
                    line-height: 28px;
                    font-weight: normal;
                    float: left;
                }

                >span {
                    margin: 9px 0 0 20px;
                    float: left;
                    font-size: 12px;
                    color: #666;
                }
            }

            .comment-input {
                margin-top: 20px;

                .comment-input-box {
                    margin-bottom: 20px;

                    .comment-input-box-left {
                        float: left;
                        width: 50px;
                        height: 50px;
                        margin-right: -100px;

                        img {
                            float: left;
                            width: 50px;
                            height: 50px;
                            margin-right: -100px;
                        }
                    }

                    .comment-input-box-right {
                        margin-left: 62px;
                        position: relative;

                        .comment-input-box-right-textarea {
                            padding-right: 14px;
                            display: block;
                            position: relative;

                            textarea {
                                height: 50px;
                                display: block;
                                width: 100%;
                                margin-right: -20px;
                                padding: 5px 6px 6px;
                                border: 1px solid #cdcdcd;
                                border-radius: 2px;
                                line-height: 19px;
                                box-sizing: content-box;
                                resize: none;
                                overflow: auto;
                                font-size: 12px;
                                color: #333;
                                outline: none;
                            }
                        }

                        .comment-input-box-btns {
                            clear: both;
                            padding-top: 10px;
                            position: relative;

                            .btn-expression {
                                float: left;
                                margin: 0px 10px 0 0;
                                cursor: pointer;
                                width: 18px;
                                height: 18px;
                                background-image: url(../../assets/images/icon.png);
                                background-position: -40px -490px;
                                overflow: hidden;
                            }

                            .btn-at {
                                float: left;
                                margin: 0px 10px 0 0;
                                cursor: pointer;
                                width: 18px;
                                height: 18px;
                                background-image: url(../../assets/images/icon.png);
                                background-position: -60px -490px;
                            }

                            .btn-comment {
                                display: block;
                                width: 46px;
                                height: 25px;
                                font-size: 12px;
                                background-image: url(../../assets/images/button.png);
                                background-position: -84px -64px;
                                color: #fff;
                                text-align: center;
                                line-height: 25px;
                                float: right;
                                cursor: pointer;
                            }

                            .comment-num {
                                float: right;
                                margin-right: 10px;
                                line-height: 25px;
                                color: #999;
                                font-size: 12px;
                            }
                        }

                        .corr {
                            position: absolute;
                            top: 11px;
                            left: -7px;
                            width: 13px;
                            height: 14px;
                            overflow: hidden;

                            em {
                                display: block;
                                font-family: "SimSun";
                                font-size: 15px;
                                font-style: normal;
                                font-weight: normal;
                                height: 10px;
                                line-height: normal;
                                color: #cdcdcd;
                            }

                            i {
                                display: block;
                                font-family: "SimSun";
                                font-size: 15px;
                                font-style: normal;
                                font-weight: normal;
                                height: 10px;
                                line-height: normal;
                                margin: -10px 0 0 1px;
                                color: #fff;
                            }
                        }

                        .emoji {
                            position: absolute;
                            top: 92px;
                            left: -18px;
                            width: 360px;
                            height: 205px;
                            padding: 17px 17px 17px 13px;
                            z-index: 100;
                            background-image: url(../../assets/images/emtbg.png);
                            background-size: 100% 100%;
                            .emoji-picker{
                                width: 100%;
                                padding: 0;
                                .emoji-footer{
                                    display: none !important;
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    .playListDetail-right {
        width: calc(100% - 709px);
    }
}
</style>